/*
 * Place.java
 * Team qq 2011
 */
package com.google.code.timetrail.backend;

/**
 * The enumerated types for the places that are visited
 * in the game
 * 
 * @author Steven Miller
 * @version 1.0
 */
public enum Place {
	//TODO replace numerals with static represenations
	/**
	 * The placeholder for being in transit
	 */
	TRANSIT(-1, "In Transit", 0, false),
	/**
	 * The starting Point
	 */
	INDEPENDECE(0, "Independence", 0, true),
	/**
	 * The place called Kansas River, 102 time units in 
	 */
	KANSAS_RIVER(102, "Kansas River", 7, false),
	/**
	 * The place called Big Blue, 185 time units in, it has a river crossing
	 */
	BIG_BLUE(185, "Big Blue", 2, false),
	/**
	 * The place called Fort Kearny, 304 time units in, it has a store
	 */
	FORT_KEARNY(304, "Fort Kearny", 0, true),
	/**
	 * place called chimney rock, 554 time units in
	 */
	CHIMNEY_ROCK(554, "Chimney Rock", 0, false),
	/**
	 * place called Fort Laramie, 640 time units in, it has a store
	 */
	FORT_LARAMIE(640, "Fort Laramie",0, true),
	/**
	 * place called Independence Rock, 830 time units in
	 */
	INDEPENDENCE_ROCK(830, "Independence Rock", 0, false),
	/**
	 * place called South Pass, 932 time units in
	 */
	SOUTH_PASS(932, "South Pass", 0, false),
	//we have the possibility for extra credit
	//to do a branching route here
	/**
	 * place called Fort Bridger, 1057 time units in, has a store
	 */
	FORT_BRIDGER(1057, "Fort Bridger", 0, true),
	/**
	 * place called Soda Springs, 1219 time units in
	 */
	SODA_SPRINGS(1219, "Soda Springs", 0, false),
	/**
	 * place called Fort Hall, 1276 time units in, it has a store
	 */
	FORT_HALL(1276, "Fort Hall", 0, true),
	/**
	 * place called Snake River Crossing, 1458 time units in, it has a river crossing
	 */
	SNAKE_RIVER_CROSSING(1458, "Snake River Crossing", 6, false),
	/**
	 * place called Fort Boise, 1572 time units in, it has a store
	 */
	FORT_BOISE(1572, "Fort Boise", 0, true),
	/**
	 * place called Blue Mountains, 1734 time units in
	 */
	BLUE_MOUNTAINS(1734, "Blue Mountains", 0, false),
	/**
	 * place called Fort Walla Walla, 1789 time units in, it has a store
	 */
	FORT_WALLA_WALLA(1789, "Fort Walla Walla", 0, true),
	/**
	 * place called Dalles, 1909 time units in
	 */
	DALLES(1909, "Dalles", 0, false),
	/** The final land, Oregon*/
	
	OREGON(1910, "Oregon" , 0, false);
	
	/** The time-distance that this place occurs in */
	private final int location;
	
	/** The name of the place*/
	private final String name;
	
	/** if there is a river crossing at that place */
	private final int riverCross;
	
	/** if there is a working store at that place*/
	private final boolean storeOpen;
	
	/**
	 * Sets up the Place types
	 * @param location the location of the place
	 * @param name the name of the place
	 * @param riverCross if the place has a river to cross
	 * @param storeOpen if there is an open store at that place
	 */
	private Place(int location, String name, int riverCross, boolean storeOpen){
		this.location = location;
		this.name = name;
		this.riverCross = riverCross;
		this.storeOpen = storeOpen;
	}

	/**
	 * Will find the next place to go to in time given your last location visited
	 * @return at the very least will return the last place you visited  
	 */
	public Place findNextPlace(){
		Place nextPlace = this;
		int nextDistance = Integer.MAX_VALUE;
		
		for(Place p : Place.values()){
			if(p.getLocation() > this.getLocation()
					&& p.getLocation() < nextDistance){
				nextPlace = p;
				nextDistance = p.getLocation();
			}
		}
		
		return nextPlace;
	}
	
	/**
	 * 
	
	 * @return the time location of the Place */
	public int getLocation(){
		return location;
	}
	
	/**
	 *
	
	 * @return the string representation of the place */
	public String getName(){
		return name;
	}
	
	/**
	 * 
	
	 * @return true if the place is a river crossing */
	public boolean hasRiverCross(){
		return riverCross != 0;
	}
	
	/**
	 * 
	 * @return the depth of the river
	 */
	public int getRiverDepth(){
	    return riverCross;
	}
	
	/**
	 * 
	
	 * @return true if the place has a store */
	public boolean hasStoreOpen(){
		return storeOpen;
	}
}
